//
//  MainTabBar.swift
//  mySina
//
//  Created by mac on 15/12/17.
//  Copyright © 2015年 tz. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(composeButton)
    }
    
    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented") //只支持纯手码
        super.init(coder: aDecoder) //支持纯手码也支持Xib/sb
        addSubview(composeButton)
    }
    //在此方法中设置所有的子视图的frame
    override func layoutSubviews() {
        super.layoutSubviews()
        let subviewW = self.bounds.width / 5
        let subviewH = self.bounds.height
        let frame = CGRectMake(0, 0, subviewW, subviewH)
        var index:CGFloat = 0
        for subview in subviews {
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                subview.frame = CGRectOffset(frame, index * subviewW, 0)
                index += (index == 1 ? 2 : 1)
            }
        }
//        composeButton.frame = CGRectMake(2 * subviewW, 0, subviewW, subviewH)
        composeButton.frame = CGRectOffset(frame, 2 * subviewW, 0)
    }
    //懒加载加号按钮
    lazy var composeButton:UIButton = UIButton(imageName: "tabbar_compose_icon_add", backImageName: "tabbar_compose_button")
}
